﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcs.Web.supply
{
    public partial class UpdateSupplyDate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int supplyPlanId = 0;

                if (Session["updateSupplyDateId"] != null)
                {
                    supplyPlanId = int.Parse(Session["updateSupplyDateId"].ToString());
                    Maticsoft.BLL.supplyPlan sm = new Maticsoft.BLL.supplyPlan();
                    Maticsoft.Model.supplyPlan s = sm.GetModel(supplyPlanId);

                    this.txt_supplyDate.Text = s.supplyDate.Value.ToShortDateString();
                }
            }
        }

        protected void btn_update_Click(object sender, EventArgs e)
        {
            string supplyDate = txt_supplyDate.Text;//供货年月
            int supplyPlanId = 0;

            if (Session["updateSupplyDateId"] != null)
            {
                supplyPlanId = int.Parse(Session["updateSupplyDateId"].ToString());
                if (!string.IsNullOrEmpty(supplyDate))
                {
                    Maticsoft.BLL.supplyPlan sm = new Maticsoft.BLL.supplyPlan();
                    Maticsoft.Model.supplyPlan s = sm.GetModel(supplyPlanId);

                    s.supplyDate = DateTime.Parse(supplyDate);

                    if (sm.Update(s))
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.returnValue=true;parent.close();</script>");
                    }


                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "请确认日期！");
                }
            }
        }
    }
}